//
//  LoginService.m
//  ReactiveObjCDemo
//
//  Created by jianzhao4 on 2017/9/5.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "LoginService.h"
#import <AFNetworking.h>

@implementation LoginService

+ (void)loginWithUsername:(NSString *)username password:(NSString *)password completionBlock:(void (^)(BOOL success))completionBlock {
    NSURL *loginUrl = [[NSBundle mainBundle] URLForResource:@"login" withExtension:nil];
    
    [[AFHTTPSessionManager manager] GET:loginUrl.absoluteString
                             parameters:nil
                               progress:nil
                                success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                                        [NSThread sleepForTimeInterval:2];
                                        dispatch_async(dispatch_get_main_queue(), ^{
                                            completionBlock((arc4random() % 2 == 0) ? YES : NO);
                                        });
                                    });
                                } failure:nil];
}

@end
